package com.itheima.mybatis;

import com.itheima.mybatis.config.HmMybaitsConfig;
import com.itheima.spring.config.HmConfig;
import com.itheima.spring.service.UserService;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @author ：sean
 * @date ：Created in 2020/6/19
 * @description ：
 * @version: 1.0
 */
public class SpringMybatisApp {
	public static void main(String args[]) throws Exception{
		//ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");

		//AnnotationConfigApplicationContext ac
		//		= new AnnotationConfigApplicationContext(HmMybaitsConfig.class);
		//
		//UserService userService = ac.getBean(UserService.class);
		//System.out.println(userService);
		//
		//Object x = ac.getBean("x");
		//System.out.println(x);

		//UserService userService = (UserService)ac.getBean("userServiceImpl");
		//userService.findUserList();
		//User user = userService.findUserByName("admin");
		//
		//TagService tagService1 = (TagService) ac.getBean("tagServiceBean");
		//TagService tagService2 = (TagService) ac.getBean("tagServiceBean");
		//
		//TagServiceBean tagServiceBean = (TagServiceBean) ac.getBean("&tagServiceBean");
		//System.out.println(tagServiceBean);

		//User user = userService.findUserByUsername("admin");
		// System.out.println(user.getPassword());
		//UserMapper userMapper1 = (UserMapper) ac.getBean(UserMapper.class);
		//System.out.println(userMapper1);
		//User user1 = userMapper1.findByUsername("admin");
		//System.out.println(user1.getPassword());

		//HmSqlSession sqlSession = new DefaultHmSqlSession();
		//UserMapper userMapper2 = sqlSession.getMapper(UserMapper.class);
		//User user2 = userMapper2.findByUsername("zhangsan");

		// 通过 registerSingleton
		//AnnotationConfigApplicationContext ac
		//		= new AnnotationConfigApplicationContext();
		//ac.register(HmConfig.class);
		//ConfigurableListableBeanFactory beanFactory = ac.getBeanFactory();
		//UserMapper userMapper = new DefaultHmSqlSession().getMapper(UserMapper.class);
		//beanFactory.registerSingleton("userMapper",userMapper);
		//ac.refresh();
		//UserService userService = ac.getBean(UserService.class);
		//userService.findUserByUsername("admin");

		// 通过UserMapperFactoryBean
		//AnnotationConfigApplicationContext ac
		//		= new AnnotationConfigApplicationContext(HmConfig.class);
		//
		//UserService userService = (UserService)ac.getBean(UserService.class);
		//userService.findUserByUsername("admin");

		// 通过单一MapperFactoryBean
		//HmUserMapperFactoryBean userMapperFactoryBean = (HmUserMapperFactoryBean)ac.getBean("&hmUserMapperFactoryBean");
		//System.out.println(userMapperFactoryBean);
		//UserMapper userMapper1 = (UserMapper)ac.getBean("hmUserMapperFactoryBean");
		//userMapper1.findByUsername("admin");

		// 通过MapperFactoryBean
		//HmMapperFactoryBean mapperFactoryBean = new HmMapperFactoryBean();
		//mapperFactoryBean.setMapperInterface(UserMapper.class);
		//UserMapper userMapper2 = (UserMapper) mapperFactoryBean.getObject();
		//userMapper2.findByUsername("admin");



	}
}
